package com.magicodex.bookkeeping.biz.common.util;

import android.widget.TextView;

import java.math.BigDecimal;
import java.time.ZonedDateTime;

/**
 * @author mh.z
 */
public class TextViewUtil {

    /**
     * 返回 TextView 的值
     *
     * @param textView
     * @return
     */
    public static String getString(TextView textView) {
        CheckUtil.notNull(textView, "textView null");
        String text = StringUtil.orEmpty(textView.getText());

        return text;
    }

    /**
     * 设置 TextView 的值
     *
     * @param textView
     * @param value
     */
    public static void setString(TextView textView, CharSequence value) {
        CheckUtil.notNull(textView, "textView null");

        String text = StringUtil.orEmpty(value);
        textView.setText(text);
    }

    /**
     * 返回 TextView 的值
     *
     * @param textView
     * @return
     */
    public static BigDecimal getBigDecimalWithDefaultFmt(TextView textView) {
        CheckUtil.notNull(textView, "textView null");

        String text = getString(textView);
        BigDecimal number = NumberUtil.parseNumberWithDefaultFmt(text);

        return number;
    }

    /**
     * 设置 TextView 的值
     *
     * @param textView
     * @param value
     */
    public static void setBigDecimalWithDefaultFmt(TextView textView, BigDecimal value) {
        CheckUtil.notNull(textView, "textView null");

        String text = NumberUtil.formatNumberWithDefaultFmt(value);
        setString(textView, text);
    }

    /**
     * 设置 TextView 的值
     *
     * @param textView
     * @param value
     */
    public static void setBigDecimalWithThousandsFmt(TextView textView, BigDecimal value) {
        CheckUtil.notNull(textView, "textView null");

        String text = NumberUtil.formatNumberWithThousandsFmt(value);
        setString(textView, text);
    }

    /**
     * 返回 TextView 的值
     *
     * @param textView
     * @return
     */
    public static ZonedDateTime getZonedDateTimeWithDefaultFmt(TextView textView) {
        CheckUtil.notNull(textView, "textView null");

        String text = getString(textView);
        ZonedDateTime date = DateUtil.parseYearDay(text);

        return date;
    }

    /**
     * 设置 TextView 的值
     *
     * @param textView
     * @param value
     */
    public static void setZonedDateTimeWithDefaultFmt(TextView textView, ZonedDateTime value) {
        CheckUtil.notNull(textView, "textView null");

        String text = DateUtil.formatYearDay(value);
        setString(textView, text);
    }

}
